package com.onepunch.controller;

/**
 * @Author: yx
 * @Date: 2025/10/30 05:46
 * @Description:
 **/

import com.github.pagehelper.PageInfo;
import com.onepunch.common.PageResult;
import com.onepunch.common.Result;
import com.onepunch.entity.Strategy;
import com.onepunch.mapper.StrategyMapper;
import com.onepunch.service.StrategyService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @projectName: onePunch
 * @package: com.onepunch.controller
 * @className: StrategyController
 * @author: yx
 * @description:
 * @date: 2025/10/30 05:46
 * @version: 1.0
 */

@RestController
@RequestMapping("/strategy")
@Tag(name = "攻略管理", description = "攻略的CRUD、分页查询等接口") // 类注释
public class StrategyController {

    @Autowired
    private StrategyService strategyService;

    /**
     *  新增攻略
     * @param strategy 攻略信息
     * @return 操作提示
     */

    @PostMapping("/add")
    @Operation(summary = "新增攻略信息", description = "传入攻略信息，新增到数据库")
    public Result addStrategy(@RequestBody Strategy strategy) {
        int i = strategyService.addStrategy(strategy);
        return i > 0 ? Result.success("新增成功") : Result.error("新增失败");
    }

    /**
     * 根据IO查询
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @Operation(summary = "根据ID查询", description = "传入id")
    public  Result findStrategyById(
            @Parameter(description = "ID不能为空", required = true)
            @PathVariable  int id) {
        return Result.success(strategyService.findStrategyById(id));
    }

    /**
     * 分页查询
     * @param strategy 攻略信息
     * @param pageNum 当前页面
     * @param pageSize 每页显示条数
     * @return
     */
    @GetMapping("/list")
    @Operation(summary = "分页列表查询", description = "传入攻略信息,返回查询列表")
    @Parameters({
            @Parameter(name = "strategy", description = "攻略信息"),
            @Parameter(name = "pageNum", description = "当前页码"),
            @Parameter(name = "pageSize", description = "每页显示条数,默认6")
    })
    public Result findAllStrategy(
            @RequestBody Strategy strategy,
            @RequestParam(defaultValue = "1")int pageNum,
            @RequestParam(defaultValue = "6")int pageSize) {
        PageResult pageInfo = strategyService.findStrategy(strategy,pageNum,pageSize);
        return Result.success(pageInfo);

    }
}
